package cn.kongwg.contorller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * @author kongwg
 * @create 2021-03-07 23:05
 */
@Controller
public class TestController {

    @PostMapping("/test/{a}/{b}")
    public String test1(@PathVariable int a, @PathVariable String b, Model model) {

        String res = a + b;
        model.addAttribute("msg", "结果为" + res);

        return "test";
    }

    @GetMapping("/test/{a}/{b}")
    public String test2(@PathVariable int a, @PathVariable String b, Model model) {

        String res = a + b + "wo shi get";
        model.addAttribute("msg", "结果为" + res);

        return "test";
    }



    @RequestMapping("/test/h1")
    public String test2(){


        return "redirect:https://www.baidu.com";


    }


    @GetMapping("/test/h2")
    public String test3(@RequestParam("username") String name,Model model){
        System.out.println(name);
        model.addAttribute("msg", name);
        return "test";
    }


    @RequestMapping("/test/e")
    public String test4(String name,Model model){

        System.out.println(name);

        model.addAttribute("msg", name);

        return "test";
    }
}
